<html>
<head><meta charset="utf-8"><title>find usages does not find field usages in patterns · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/find.20usages.20does.20not.20find.20field.20usages.20in.20patterns.html">find usages does not find field usages in patterns</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="212840860"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/find%20usages%20does%20not%20find%20field%20usages%20in%20patterns/near/212840860" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/find.20usages.20does.20not.20find.20field.20usages.20in.20patterns.html#212840860">(Oct 09 2020 at 15:30)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">S</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">field</span><span class="o">&lt;|&gt;</span>: <span class="kt">u8</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">f</span><span class="p">(</span><span class="n">s</span>: <span class="nc">S</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">match</span><span class="w"> </span><span class="n">s</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">S</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">field</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>

<p>Invoking find usages on the above snippet does not find the field usage in the match. This happens presumably because ident patterns contain a <code>ast::Name</code>, not an <code>ast::NameRef</code>. What would be the correct way to fix this?</p>
<p>It seems to me that we'd have to change <code>classify_name_ref</code> to take something like <code>Either&lt;ast::Name, ast::NameRef&gt;</code>, or add an extra method that works with <code>ast::Name</code>. Of course, changing the AST to use <code>ast::NameRef</code> would also work, but IIRC that's intentional?</p>



<a name="212842023"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/find%20usages%20does%20not%20find%20field%20usages%20in%20patterns/near/212842023" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/find.20usages.20does.20not.20find.20field.20usages.20in.20patterns.html#212842023">(Oct 09 2020 at 15:39)</a>:</h4>
<p>Ah nevermind, <code>classify_name</code> already exists</p>



<a name="212967248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/find%20usages%20does%20not%20find%20field%20usages%20in%20patterns/near/212967248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/find.20usages.20does.20not.20find.20field.20usages.20in.20patterns.html#212967248">(Oct 11 2020 at 14:18)</a>:</h4>
<p>Yeah, <code>classify</code> infra is well-prepared for handing such special cases of mixed ref/def (its actually <strong>the</strong> reason for this infra to exist in the first place)</p>



<a name="212967310"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/find%20usages%20does%20not%20find%20field%20usages%20in%20patterns/near/212967310" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/find.20usages.20does.20not.20find.20field.20usages.20in.20patterns.html#212967310">(Oct 11 2020 at 14:20)</a>:</h4>
<p>Fun bit of trivia -- Kotlin devs have a royal pain with implementing find usages for fields, as named fields can be used positionaly:</p>
<p><a href="https://pl.kotl.in/QL0aOQkDj">https://pl.kotl.in/QL0aOQkDj</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>